﻿
//***********************************************************************
// * Module:   MsjHzSyznlhHandler
// * 作者:  XWG
// * Modified: 2013-05-29
// * Purpose: Definition of the Class MsjHzSyznlhHandler 业务逻辑处理Handler类
// ***********************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Data;
using XWG.Framework.Query;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using XWG.Framework.MSException;
using XWG.Framework.AuthUtility;
using XWG.Framework.AuthEntity;
using XWG.Framework.AuthSPConst;
using XWG.Framework.AuthBLL;
using XWG.JWBST.JWBSTEntity;
using XWG.JWBST.JWBSTSPConst;
using XWG.JWBST.JWBSTBLL;
using System.Collections;
using XWG.Framework;
using JWBSTAPP.CommonClass;

namespace JWBSTAPP.AjaxServer
{
    /// <summary>
    /// MsjHzSyznlhHandler 的摘要说明
    /// </summary>
    public class MsjHzSyznlhHandler : JWBSTAPP.CommonClass.HttpHandlerBase, System.Web.SessionState.IRequiresSessionState
    {
      
        #region 添加记录
      /// <summary>
      /// 添加记录
      /// </summary>
      protected void AddRecord()
        {
             HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //初始化返回类型
            try
            {           
            MsjHzSyznlh mMsjHzSyznlh = new MsjHzSyznlh();
            mMsjHzSyznlh.Syid = Guid.NewGuid().ToString(); //主键
                 mMsjHzSyznlh.Fqxm = context.Request.Form["texFqxm"]; //父亲姓名
                 mMsjHzSyznlh.Fqxb = context.Request.Form["selFqxb"]; //父亲性别(字典)
                 mMsjHzSyznlh.Fqnl = Convert.ToDecimal(context.Request.Form["texFqnl"]); //父亲年龄
                 mMsjHzSyznlh.Fqmz = context.Request.Form["texFqmz"]; //父亲民族(字典)
                 mMsjHzSyznlh.Fqwhcd = context.Request.Form["texFqwhcd"]; //父亲文化程度(字典)
                 mMsjHzSyznlh.Fqsfzh = context.Request.Form["texFqsfzh"]; //父亲身份证号码
                 mMsjHzSyznlh.Fqjkzk = context.Request.Form["texFqjkzk"]; //父亲健康状况
                 mMsjHzSyznlh.Fqhyzk = context.Request.Form["texFqhyzk"]; //父亲婚姻状况(字典)
                 mMsjHzSyznlh.Fqzy = context.Request.Form["texFqzy"]; //父亲职业
                 mMsjHzSyznlh.Fqgzdw = context.Request.Form["texFqgzdw"]; //父亲工作单位
                 mMsjHzSyznlh.Fqlxdh = context.Request.Form["texFqlxdh"]; //父亲联系电话
                 mMsjHzSyznlh.Fqjtzz = context.Request.Form["texFqjtzz"]; //父亲家庭住址
                 mMsjHzSyznlh.Mqxm = context.Request.Form["texMqxm"]; //母亲姓名
                 mMsjHzSyznlh.Mqxb = context.Request.Form["selMqxb"]; //母亲性别(字典)
                 mMsjHzSyznlh.Mqnl = Convert.ToDecimal(context.Request.Form["texMqnl"]); //母亲年龄
                 mMsjHzSyznlh.Mqmz = context.Request.Form["texMqmz"]; //母亲民族(字典)
                 mMsjHzSyznlh.Mqwhcd = context.Request.Form["texMqwhcd"]; //母亲文化程度(字典)
                 mMsjHzSyznlh.Mqsfzh = context.Request.Form["texMqsfzh"]; //母亲身份证号码
                 mMsjHzSyznlh.Mqjkzk = context.Request.Form["texMqjkzk"]; //母亲健康状况
                 mMsjHzSyznlh.Mqhyzk = context.Request.Form["texMqhyzk"]; //母亲婚姻状况
                 mMsjHzSyznlh.Mqzy = context.Request.Form["texMqzy"]; //母亲职业
                 mMsjHzSyznlh.Mqgzdw = context.Request.Form["texMqgzdw"]; //母亲工作单位
                 mMsjHzSyznlh.Mqlxdh = context.Request.Form["texMqlxdh"]; //母亲联系电话
                 mMsjHzSyznlh.Mqjtzz = context.Request.Form["texMqjtzz"]; //母亲家庭住址
                 mMsjHzSyznlh.Jtnsr = Convert.ToDecimal(context.Request.Form["texJtnsr"]); //家庭年收入
                 mMsjHzSyznlh.Xyznqk = Convert.ToDecimal(context.Request.Form["texXyznqk"]); //现有子女情况
                 mMsjHzSyznlh.Xm = context.Request.Form["texXm"]; //姓名
                 mMsjHzSyznlh.Xb = context.Request.Form["selXb"]; //性别(字典)
                 mMsjHzSyznlh.Nl = Convert.ToDecimal(context.Request.Form["texNl"]); //年龄
                 mMsjHzSyznlh.Mz = context.Request.Form["texMz"]; //民族(字典)
                 mMsjHzSyznlh.Jkzk = context.Request.Form["texJkzk"]; //健康状况
                 mMsjHzSyznlh.Sfzh = context.Request.Form["texSfzh"]; //身份证号
                 mMsjHzSyznlh.Xhkszd = context.Request.Form["texXhkszd"]; //现户口所在地
                 mMsjHzSyznlh.Syzbldw = context.Request.Form["texSyzbldw"]; //收养证办理单位
                 mMsjHzSyznlh.Sljg = context.Request.Form["texSljg"]; //受理机关(字典)
                 mMsjHzSyznlh.Bz = context.Request.Form["texBz"]; //备注
                 mMsjHzSyznlh.Cjsj = System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); //创建时间(2013-05-28 09:13:01)
                 mMsjHzSyznlh.Cjr =Convert.ToString(context.Session["UserID"]); //创建人(人员ID)
                 
                 //mMsjHzSyznlh.Cjrdw = context.Request.Form["texCjrdw"]; //创建单位(单位ID)
                 //mMsjHzSyznlh.Xgr = context.Request.Form["texXgr"]; //修改人(人员ID)
                 //mMsjHzSyznlh.Xgrdw = context.Request.Form["texXgrdw"]; //修改人单位(单位ID)
                 //mMsjHzSyznlh.Xgsj = context.Request.Form["texXgsj"]; //修改时间(2013-05-28 09:13:01)
                 mMsjHzSyznlh.Enabled = Enabled.TRUE; //是否有效（1有效，0无效）
                 mMsjHzSyznlh.Movesign = "0"; //是否传输（1已，0未）
            
            mResultModel = MsjHzSyznlhBLL.Insert(mMsjHzSyznlh,context.Session["UserID"], true); //新建操作
            context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, string.Empty);
                mResultModel.ErrorCode = -9999;
                mResultModel.ISSucceed = false;
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
        }
        #endregion
        
        #region 删除记录
      /// <summary>
      /// 删除记录
      /// </summary>
       protected void DeleteRecord()
        {
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //声明返回类型
            string paramKey = context.Request.Params["id"];
            try
            {
              if (string.IsNullOrEmpty(paramKey))
                {
                    mResultModel.ErrorCode = -9991;
                    mResultModel.ISSucceed = false;
                    context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回    
                    return ;
                }
                
                MsjHzSyznlh mMsjHzSyznlh = new MsjHzSyznlh(); 
                if (!string.IsNullOrEmpty(paramKey))
                {
                    mResultModel = MsjHzSyznlhBLL.Delete(paramKey, context.Session["UserID"], true); //删除对应的信息
                    context.Response.Write(JsonConvert.SerializeObject(mResultModel));  //序列化后返回
                }
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, string.Empty); //写入异常日志
                mResultModel.ErrorCode = -9999; //-9999代码是系统异常通用代码
                mResultModel.ISSucceed = false; //行为执行失败
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }            
        } 
        #endregion
     
        #region 修改记录
      /// <summary>
      /// 修改记录
      /// </summary>
      protected void EditRecord()
        {
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //初始化返回类型
           MsjHzSyznlh mMsjHzSyznlh = new MsjHzSyznlh();

            string paramKey = context.Request.Params["id"];
            try
            {
                
                if(string.IsNullOrEmpty(paramKey))
                {
                    mResultModel.ErrorCode = -9991;
                    mResultModel.ISSucceed = false;
                    context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回    
                    return ;
                }
                   mMsjHzSyznlh = MsjHzSyznlhBLL.Load(paramKey); //根据键值获取实体信息
                    if (mMsjHzSyznlh != null)
                    {
                 mMsjHzSyznlh.Fqxm = context.Request.Form["texFqxm"]; //父亲姓名
                 mMsjHzSyznlh.Fqxb = context.Request.Form["selFqxb"]; //父亲性别(字典)
                 mMsjHzSyznlh.Fqnl = Convert.ToDecimal(context.Request.Form["texFqnl"]); //父亲年龄
                 mMsjHzSyznlh.Fqmz = context.Request.Form["texFqmz"]; //父亲民族(字典)
                 mMsjHzSyznlh.Fqwhcd = context.Request.Form["texFqwhcd"]; //父亲文化程度(字典)
                 mMsjHzSyznlh.Fqsfzh = context.Request.Form["texFqsfzh"]; //父亲身份证号码
                 mMsjHzSyznlh.Fqjkzk = context.Request.Form["texFqjkzk"]; //父亲健康状况
                 mMsjHzSyznlh.Fqhyzk = context.Request.Form["texFqhyzk"]; //父亲婚姻状况(字典)
                 mMsjHzSyznlh.Fqzy = context.Request.Form["texFqzy"]; //父亲职业
                 mMsjHzSyznlh.Fqgzdw = context.Request.Form["texFqgzdw"]; //父亲工作单位
                 mMsjHzSyznlh.Fqlxdh = context.Request.Form["texFqlxdh"]; //父亲联系电话
                 mMsjHzSyznlh.Fqjtzz = context.Request.Form["texFqjtzz"]; //父亲家庭住址
                 mMsjHzSyznlh.Mqxm = context.Request.Form["texMqxm"]; //母亲姓名
                 mMsjHzSyznlh.Mqxb = context.Request.Form["selMqxb"]; //母亲性别(字典)
                 mMsjHzSyznlh.Mqnl = Convert.ToDecimal(context.Request.Form["texMqnl"]); //母亲年龄
                 mMsjHzSyznlh.Mqmz = context.Request.Form["texMqmz"]; //母亲民族(字典)
                 mMsjHzSyznlh.Mqwhcd = context.Request.Form["texMqwhcd"]; //母亲文化程度(字典)
                 mMsjHzSyznlh.Mqsfzh = context.Request.Form["texMqsfzh"]; //母亲身份证号码
                 mMsjHzSyznlh.Mqjkzk = context.Request.Form["texMqjkzk"]; //母亲健康状况
                 mMsjHzSyznlh.Mqhyzk = context.Request.Form["texMqhyzk"]; //母亲婚姻状况
                 mMsjHzSyznlh.Mqzy = context.Request.Form["texMqzy"]; //母亲职业
                 mMsjHzSyznlh.Mqgzdw = context.Request.Form["texMqgzdw"]; //母亲工作单位
                 mMsjHzSyznlh.Mqlxdh = context.Request.Form["texMqlxdh"]; //母亲联系电话
                 mMsjHzSyznlh.Mqjtzz = context.Request.Form["texMqjtzz"]; //母亲家庭住址
                 mMsjHzSyznlh.Jtnsr = Convert.ToDecimal(context.Request.Form["texJtnsr"]); //家庭年收入
                 mMsjHzSyznlh.Xyznqk = Convert.ToDecimal(context.Request.Form["texXyznqk"]); //现有子女情况
                 mMsjHzSyznlh.Xm = context.Request.Form["texXm"]; //姓名
                 mMsjHzSyznlh.Xb = context.Request.Form["selXb"]; //性别(字典)
                 mMsjHzSyznlh.Nl = Convert.ToDecimal(context.Request.Form["texNl"]); //年龄
                 mMsjHzSyznlh.Mz = context.Request.Form["texMz"]; //民族(字典)
                 mMsjHzSyznlh.Jkzk = context.Request.Form["texJkzk"]; //健康状况
                 mMsjHzSyznlh.Sfzh = context.Request.Form["texSfzh"]; //身份证号
                 mMsjHzSyznlh.Xhkszd = context.Request.Form["texXhkszd"]; //现户口所在地
                 mMsjHzSyznlh.Syzbldw = context.Request.Form["texSyzbldw"]; //收养证办理单位
                 mMsjHzSyznlh.Sljg = context.Request.Form["texSljg"]; //受理机关(字典)
                 mMsjHzSyznlh.Bz = context.Request.Form["texBz"]; //备注
                 //mMsjHzSyznlh.Cjsj = context.Request.Form["texCjsj"]; //创建时间(2013-05-28 09:13:01)
                 //mMsjHzSyznlh.Cjr = context.Request.Form["texCjr"]; //创建人(人员ID)
                 //mMsjHzSyznlh.Cjrdw = context.Request.Form["texCjrdw"]; //创建单位(单位ID)
                 mMsjHzSyznlh.Xgr = context.Session["UserID"].ToString(); //修改人(人员ID)
                 mMsjHzSyznlh.Xgsj = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); //修改时间(2013-05-28 09:13:01)
                 //mMsjHzSyznlh.Xgrdw = context.Request.Form["texXgrdw"]; //修改人单位(单位ID)
                 //mMsjHzSyznlh.Enabled = Enabled.TRUE; //是否有效（1有效，0无效）
                 //mMsjHzSyznlh.Movesign = context.Request.Form["texMovesign"]; //是否传输（1已，0未）
            
            mResultModel = MsjHzSyznlhBLL.Update(mMsjHzSyznlh,context.Session["UserID"], true); //新建操作
                 }
                else
                 {
                mResultModel.ErrorCode = -9990; //没有获取所需的信息，信息可能已被删除
                mResultModel.ISSucceed = false;               
                 }
                
            context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, string.Empty);
                mResultModel.ErrorCode = -9999;
                mResultModel.ISSucceed = false;
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
        }    
        #endregion 
        
        #region 获取实体记录
      /// <summary>
      /// 获取实体记录
      /// </summary>
        protected void GetModel()
        {
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
             ResultModel mResultModel = new ResultModel(); //初始化返回类型
            string paramKey = context.Request.Params["id"];
            string json = string.Empty;
            try
            {
                MsjHzSyznlh mMsjHzSyznlh = new MsjHzSyznlh(); //声明实体
                if (!string.IsNullOrEmpty(paramKey))
                {
                    mMsjHzSyznlh = MsjHzSyznlhBLL.Load(paramKey); //根据键值获取管理员
                    if (mMsjHzSyznlh != null)
                    {
                        json = JsonConvert.SerializeObject(mMsjHzSyznlh);
                        Hashtable hashtable = new Hashtable();
                        if (!string.IsNullOrEmpty(mMsjHzSyznlh.Fqxb))
                        {
                            hashtable.Add("FqxbTxt", mMsjHzSyznlh.Fqxb == "0" ? "男" : "女");
                        }
                        if (!string.IsNullOrEmpty(mMsjHzSyznlh.Mqxb))
                        {
                            hashtable.Add("MqxbTxt", mMsjHzSyznlh.Mqxb == "0" ? "男" : "女");
                        }
                        if (!string.IsNullOrEmpty(mMsjHzSyznlh.Xb))
                        {
                            hashtable.Add("XbTxt", mMsjHzSyznlh.Xb == "0" ? "男" : "女");
                        }
                        if (!string.IsNullOrEmpty(mMsjHzSyznlh.Enabled))
                        {
                            hashtable.Add("EnabledTxt", mMsjHzSyznlh.Enabled == "1" ? "有效" : "无效");
                        }
                        json = JsonString.AddAttribute(json, hashtable);
                    }
                }
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, string.Empty);
                mResultModel.ErrorCode = -9990;
                mResultModel.ISSucceed = false;
                json = JsonConvert.SerializeObject(mResultModel);
            }
            
            context.Response.Write(json);
        }
        #endregion
      
        #region 获取数据
        /// <summary>
      /// 获取数据记录
      /// </summary>
       protected void QueryRecord()
        {
            TableMessage tm = new TableMessage();
            HearderMessage hm = new HearderMessage();
            List<HearderMessage> list = new List<HearderMessage>();
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            string pageSize = context.Request.Form["pageSize"];
            string pageIndex = context.Request.Form["pageIndex"];
            string xm = context.Request.Form["texXm"]; //姓名
            string xb = context.Request.Form["selXb"]; //性别(字典)
            string sfzh = context.Request.Form["texSfzh"]; //身份证号
            string xhkszd = context.Request.Form["texXhkszd"]; //现户口所在地
            if (String.IsNullOrEmpty(pageSize) || String.IsNullOrEmpty(pageIndex) || !AnyString.IsNumeric(pageSize) || !AnyString.IsNumeric(pageIndex))
            { 
                return;
            }
            
            DataTable dtMsjHzSyznlh = new DataTable();
            int intPageSize = Convert.ToInt32(pageSize);
            int intPageIndex = Convert.ToInt32(pageIndex);
            QueryByPage q=new QueryByPage();
            QueryInfo qInfo=new QueryInfo();

            SqlConditionList conditionList = new SqlConditionList();


            if (!String.IsNullOrEmpty(xm))
            {
                conditionList.AddLogic(new SqlConditionList.SqlCondition(SqlCompareOper.LIKE, MsjHzSyznlhConst.Columns.Xm, "%" + xm + "%"), SqlLogicOper.AND_LOGIC);
            }

            if (!String.IsNullOrEmpty(xb))
            {
                conditionList.AddLogic(new SqlConditionList.SqlCondition(SqlCompareOper.EQUAL, MsjHzSyznlhConst.Columns.Xb, xb), SqlLogicOper.AND_LOGIC);
            }

            if (!String.IsNullOrEmpty(sfzh))
            {
                conditionList.AddLogic(new SqlConditionList.SqlCondition(SqlCompareOper.LIKE, MsjHzSyznlhConst.Columns.Sfzh, "%" + sfzh + "%"), SqlLogicOper.AND_LOGIC);
            }

            if (!String.IsNullOrEmpty(xhkszd))
            {
                conditionList.AddLogic(new SqlConditionList.SqlCondition(SqlCompareOper.LIKE, MsjHzSyznlhConst.Columns.Xhkszd, "%" + xhkszd + "%"), SqlLogicOper.AND_LOGIC);
            }
            string sqlWhere = conditionList.ToSql();

            dtMsjHzSyznlh = q.GetRecordByPage("*", sqlWhere, string.Empty, intPageSize, intPageIndex, MsjHzSyznlhConst.TableName, MsjHzSyznlhConst.FieldKey, string.Empty).Tables[0];
           //翻译表DataTable中的特殊字段
            Hashtable columnData = new Hashtable();
            columnData.Add("0", "男");
            columnData.Add("1", "女");

            ResolveColumn resolveColumn = new ResolveColumn();
            resolveColumn.oldColumnName = "XB";
            resolveColumn.newType = typeof(String);
            resolveColumn.columnData = columnData;

            ResolveColumn[] resolveColumnArray = new ResolveColumn[] { resolveColumn };

            dtMsjHzSyznlh = ResolveReference.ResolveDataTable(dtMsjHzSyznlh, resolveColumnArray);

            if (dtMsjHzSyznlh != null && dtMsjHzSyznlh.Rows.Count > 0)
             {
                 for (int i = 0; i < dtMsjHzSyznlh.Columns.Count; i++)
                 {
                     hm = new HearderMessage();
                     hm.name = dtMsjHzSyznlh.Columns[i].Caption;
                     list.Add(hm);
                 }
                
                 tm.Header = list;
                 tm.data = dtMsjHzSyznlh;
                 tm.totalCount = Convert.ToString((int)q.RowCount);
             }
            
            string json = JsonConvert.SerializeObject(tm);
            context.Response.Write(json);
        }
       
       protected void QueryGtRecord()
        {
           HttpContext context = HttpContext.Current;
           context.Response.ContentType = "text/plain";

           QueryInfo info = new QueryInfo();
           QueryByPage page = new QueryByPage();
           info.FieldKey = MsjHzSyznlhConst.FieldKey;
           info.PageIndex = 1;
           info.PageSize = 0;
           info.QTableName = MsjHzSyznlhConst.TableName;
           info.SelectFields = "*";

           info.Where = string.Empty;
           DataSet ds = page.GetRecordByPage(info);
           DataTable table = new DataTable();
        
           if (ds.Tables.Count > 0)
           {
               table = page.GetRecordByPage(info).Tables[0];
           }
           string json = JsonConvert.SerializeObject(table);
           context.Response.Write(json);
        }
         #endregion           
}
}
 
 
